<template>
	<view class="qrcode">
		<view class="dheader">
			<view class="shop">
				<image :src="shop_info.category_image" mode="aspectFill" class="Boutique"></image>
				<view class="title">
					{{shop_info.shop_name}}
				</view>
				<view class="right" @click="toggle">
					<view class="size">
						切换
					</view>
					<image :src="$IMG_URL('/static/home/indicate.png')" mode="" class="icon" ></image>
				</view>
			</view>
			<view class="search">
				<u-search placeholder="搜索订单" :show-action="false" shape="square" v-model="query.search"
					@change="$u.debounce(getSearch,500)"></u-search>
			</view>
		</view>
		<view class="tab">
			<view v-for="(item,index) in tabList" :key="index" class="tabIndex" @click="changeIndex(index)">
				<view :class="activeIndex == index ?'tabsize1':'tabsize2'">
					{{item}}
				</view>
				<view class="active">
					<view class="empty" v-if="activeIndex == index">
					</view>
				</view>
			</view>
		</view>
		<scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="scrolltolower">
			<view class="comlum_Y" v-if="list.length">
				<view v-for="(item,index) in list" :key="index" class="order" @click.stop="routeDeatil(item, index)">
					<view class="top">
						<view class="left">
							{{item.time?item.time:'暂无时间'}}
						</view>
						<view class="right">
							<text class="size">{{item.state_str}}</text>
							<u-icon name="arrow-right" color="#999999" size="14"></u-icon>
						</view>
					</view>
					<view class="center">
						<image :src="item.image" mode="aspectFill" class="card"></image>
						<view class="right">
							<view class="one">
								<view class="name">
									{{item.title}}
								</view>
								<view class="price">
									<text class="size1">￥</text>
									<text class="size2">{{item.cost}}</text>
								</view>
							</view>
							<view class="one">
								<view class="name">
								</view>
								<view class="price">
									<text class="size3">已优惠￥{{item.coupon_cost}}</text>
								</view>
							</view>
							<view class="two">
								<view class="left1">
									{{item.form_str}}
								</view>
								<view class="right1">
									{{item.num_str}}
								</view>
							</view>
						</view>
					</view>
					<view class="foot_bom">
						<view class="left2">
							<text v-if="item.form == 'accomplish'">领取人</text>
						</view>
						<view class="btn" v-if="item.form == 'pay'" @click.stop="openShow(item)">
							支付码
						</view>
						<view class="btn" v-if="item.form == 'draw'" @click.stop="openShow(item)">
							领取码
						</view>
						<view class="right2" v-if="JSON.stringify(item.user_info) !== '{}'">
							<image :src="item.user_info.avatar" mode="aspectFill" class="img"></image>
							<text class="size8">{{item.user_info.nickname}}</text>
						</view>
					</view>
				</view>
				<u-loadmore :status="status" />
			</view>
			<empty v-else :content="!activeIndex?'订单':activeIndex == 1 ?'会员卡订单':'课程订单'"></empty>
		</scroll-view>
		<view class="foot">
			<view class="btn" @click="addorder">
				添加订单
			</view>
		</view>
		<Qcode :WechatCodeShow="codeShow" :code="qrcodeQuery.qrcode" :title="qrcodeQuery.title"
			:content="qrcodeQuery.explain" :btn="qrcodeQuery.button" @close="close" @sure="coseSure"></Qcode>
		<FieldPopupVue :popupShow="popupShow" :FieldList="Field" @sure="sure" @changeActiveIndex="changeActiveIndex"
			:activeIndex="FieldIndex"></FieldPopupVue>
	</view>
</template>

<script>
	import FieldPopupVue from '../../pages/user/components/Field-popup.vue'
	import Qcode from './components/Qcode.vue'
	import empty from './components/empty.vue'
	import {
		atShop,
		storeorderList,
		storeorderQrcode,
		storeorderPoster
	} from '@/api/manager.js'
	export default {
		components: {
			FieldPopupVue,
			Qcode,
			empty
		},
		data() {
			return {
				shop_info: {},
				query: {
					form: 'all',
					search: '',
					page: 1
				},
				status: 'loadmore', //当前状态
				popupShow: false,
				Field: [],
				FieldIndex: -1,
				codeShow: false,
				code: '',
				tabList: [
					'全部',
					'会员卡',
					'课程'
				],
				qrcodeQuery: {},
				// title:'私教课(减脂塑形)支付码',
				content: '请使用支付宝/微信扫码支付',
				shopName: '',
				// btnName:'保存支付码',
				activeIndex: 0,
				list: [],
				poster:'',
				orderId:''
			}
		},
		onLoad() {
			this.getatShop()

		},
		onShow() {
			this.list = []
			this.query.page = 1
			this.getStoreOrderList()
		},
		methods: {
			scan(){
				let t = this
				uni.scanCode({
					success: function(saoma) {
						console.log('saoma', saoma);
						if (saoma.errMsg === 'scanCode:ok') {
							const obj = JSON.parse(saoma.result)

						} else {
							uni.showToast({
								title: '扫码失败',
								icon: 'none'
							})
						}
				
					}
				});
			},
			getSearch() {
				this.list = []
				this.query.page = 1
				this.getStoreOrderList()

			},
			scrolltolower() {
				this.query.page++
				this.getStoreOrderList()
			},
			getStoreOrderList() {
				storeorderList(this.query).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						const list = []
						this.status = 'loading'
						if (this.query.page > res.data.all_page) {
							console.log('nomore');
							this.status = 'nomore'
							return false
						} else {
							console.log('more');
							this.status = 'more'
							this.list = this.list.concat(res.data.list)
						}

						console.log('list', this.list);
					}
				})
			},
			getatShop(e) {
				atShop(e).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.shop_info = res.data
					}
				})
			},
			routeDeatil(item, index) {
				uni.navigateTo({
					url: 'orderdeatil?order_id=' + item.order_id
				})
			},
			toggle() {
				console.log(11);
				this.popupShow = true
			},
			changeIndex(index) {
				if (this.activeIndex != index) {
					if (!index) {
						this.query.form = 'all'
					} else if (index == 1) {
						this.query.form = 'card'
					} else {
						this.query.form = 'course'
					}
					this.activeIndex = index
					this.list = []
					this.query.page = 1
					this.getStoreOrderList()
				}
			},
			changeActiveIndex(item, index) {
				this.FieldIndex = index
				this.getatShop({
					shop_id: item.shop_id
				})
				this.list = []
				this.query.page = 1
				this.getStoreOrderList()
			},
			sure() {
				this.popupShow = false
			},

			openShow(item) {
				console.log('item', item);
				this.orderId = item.order_id
				storeorderQrcode({
					order_id: item.order_id
				}).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.qrcodeQuery = res.data
						this.codeShow = true
					}
				})

			},
			close() {
				this.codeShow = false
			},
			getstoreorderPoster(){
				storeorderPoster({
					order_id: this.orderId
				}).then(({data:res})=>{
					console.log('res', res);
					if(res.code == 1){
						this.$SAVERIMG(res.data.poster)
					}
				})
			},
			coseSure() {
				this.getstoreorderPoster()
				this.codeShow = false
			},
			addorder() {
				uni.navigateTo({
					url: 'addOrder'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #e9e9e9;
	}

	.qrcode {
		display: flex;
		flex-direction: column;
		align-items: center;

		.dheader {
			width: 750rpx;
			height: 184rpx;
			background: #ffffff;
			padding: 26rpx 34rpx 0;

			.shop {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-bottom: 22rpx;

				.Boutique {
					width: 114rpx;
					height: 36rpx;
					margin-right: 12rpx;
				}

				.title {
					flex: 1;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC-Bold;
					font-weight: 700;
					text-align: left;
					color: #333333;
				}

				.right {
					display: flex;
					flex-direction: row;
					align-items: center;

					.size {
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						color: #666666;
						margin-right: 8rpx;
					}

					.icon {
						width: 10rpx;
						height: 16rpx;
					}
				}
			}

			.search {
				width: 100%;
			}


		}

		.tab {
			width: 750rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-around;
			background: #ffffff;

			.tabIndex {
				display: flex;
				flex-direction: column;
				align-items: center;

				.tabsize1 {
					height: 44rpx;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Heavy;
					font-weight: 800;
					text-align: center;
					color: #73F0EA;
					letter-spacing: 0.7rpx;

				}

				.tabsize2 {
					height: 44rpx;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					text-align: center;
					color: #666666;
					letter-spacing: 0.7rpx;

				}

				.active {
					margin-top: 12rpx;
					width: 44rpx;
					height: 8rpx;

					.empty {
						width: 100%;
						height: 100%;
						background: #73F0EA;
						border: 2rpx solid rgba(0, 0, 0, 0.00);
						border-radius: 2rpx;
					}
				}
			}
		}

		.scroll-Y {
			width: 100%;
			height: 72vh;

			.comlum_Y {
				display: flex;
				flex-direction: column;
				align-items: center;
				padding-top: 24rpx;

				.order {
					width: 702rpx;
					background: #ffffff;
					border-radius: 16rpx;
					padding: 0 24rpx;
					margin-bottom: 24rpx;

					.top {
						display: flex;
						flex-direction: row;
						align-items: center;
						padding: 28rpx 0;
						width: 100%;
						border-bottom: 2rpx solid #f8f8f8;

						.left {
							flex: 1;
							font-size: 24rpx;
							font-family: PingFang SC, PingFang SC-Bold;
							font-weight: 700;
							text-align: left;
							color: #333333;
						}

						.right {
							display: flex;
							flex-direction: row;
							align-items: center;

							.size {
								margin-right: 7rpx;
								font-size: 24rpx;
								font-family: PingFang SC, PingFang SC-Medium;
								font-weight: 500;
								text-align: right;
								color: #999999;
							}
						}
					}

					.center {
						display: flex;
						flex-direction: row;
						width: 100%;
						padding: 26rpx 0 32rpx;

						.card {
							width: 160rpx;
							height: 120rpx;
							margin-right: 20rpx;
						}

						.right {
							display: flex;
							flex-direction: column;
							flex: 1;

							.one {
								display: flex;
								flex-direction: row;
								align-items: center;

								.name {
									font-size: 32rpx;
									font-family: PingFang SC, PingFang SC-Bold;
									font-weight: 700;
									text-align: left;
									color: #333333;
									flex: 1;
								}

								.price {
									display: flex;
									flex-direction: row;
									align-items: baseline;
									font-family: DIN, DIN-Bold;
									color: #f37364;

									.size1 {
										font-size: 24rpx;
										font-weight: 700;
									}

									.size2 {
										font-size: 32rpx;
										font-weight: 700;
									}

									.size3 {
										font-size: 24rpx;
										color: #f37364;
									}
								}
							}

							.two {
								display: flex;
								flex-direction: row;
								align-items: center;

								.left1 {
									font-size: 24rpx;
									font-family: PingFang SC, PingFang SC-Medium;
									font-weight: 500;
									text-align: left;
									color: #999999;
									flex: 1;
								}

								.right1 {
									font-size: 24rpx;
									font-family: PingFang SC, PingFang SC-Regular;
									font-weight: 400;
									text-align: right;
									color: #666666;
								}
							}
						}
					}

					.foot_bom {
						width: 100%;
						display: flex;
						flex-direction: row;
						align-items: baseline;
						padding-bottom: 24rpx;

						.left2 {
							flex: 1;
							display: flex;
							flex-direction: row;
							align-items: center;
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Medium;
							font-weight: 500;
							text-align: right;
							color: #000000;
						}

						.btn {
							transform: rotateZ(360deg);
							width: 152rpx;
							height: 64rpx;
							background: #73F0EA;
							border: 1rpx solid #73F0EA;
							border-radius: 16rpx;
							font-size: 28rpx;
							font-family: PingFang SC, PingFang SC-Bold;
							font-weight: 700;
							text-align: center;
							color: #ffffff;
							display: flex;
							align-items: center;
							justify-content: center;
						}

						.right2 {
							display: flex;
							flex-direction: row;
							align-items: center;

							.img {
								width: 40rpx;
								height: 40rpx;
								background: rgba(0, 0, 0, 0.00);
								border-radius: 50%;
								margin-right: 8rpx;
							}

							.size8 {
								font-size: 28rpx;
								font-family: PingFang SC, PingFang SC-Medium;
								font-weight: 500;
								text-align: left;
								color: #333333;
							}
						}
					}
				}
			}
		}

		.foot {
			position: fixed;
			bottom: 0;
			width: 750rpx;
			height: 158rpx;
			background: #ffffff;
			box-shadow: 0rpx 8rpx 28rpx 0rpx rgba(166, 179, 194, 0.30);
			padding-top: 10rpx;
			display: flex;
			justify-content: center;

			.btn {
				width: 710rpx;
				height: 88rpx;
				background: #73F0EA;
				border-radius: 16rpx;
				font-size: 34rpx;
				font-family: PingFang SC, PingFang SC-Bold;
				font-weight: 700;
				text-align: center;
				color: #ffffff;
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}
	}
</style>